// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129

const {
	success,
	error
} = require('response')


const db = uniCloud.databaseForJQL();

module.exports = {

	async updateUser(id, user) {
		var instance = await db.collection('users').where({
			'_id': id
		}).update(user)
		return instance;
	},

	async addUser(user) {
		var res = await db.collection('users').where({
			wx_openid: user.wx_openid
		}).get();
		if (res.data.length > 0) {
			return res.data[0]
		} else {
			await db.collection('users').add(user);
			var res = await db.collection('users').where({
				wx_openid: user.wx_openid
			}).get();
			return res.data[0]
		}
	}
}